package org.tnaggs.project.security;

import java.util.ArrayList;
import java.util.Collection;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.tnaggs.project.model.Contact;

public class ContactUser implements UserDetails{

	
	private Contact contact;
	private SimpleGrantedAuthority role;
	
	public ContactUser(Contact newCon, String roleP) {
		setContact(newCon);
		role = new SimpleGrantedAuthority(roleP);
	}
	
	@Override
	public Collection<? extends GrantedAuthority> getAuthorities() {
		ArrayList<GrantedAuthority> roles = new ArrayList<GrantedAuthority>();
		roles.add(role);
		return roles;
	}

	@Override
	public String getPassword() {
		return contact.getPassword();
	}

	@Override
	public String getUsername() {
		return contact.getEmail();
	}

	@Override
	public boolean isAccountNonExpired() {
		return true;
	}

	@Override
	public boolean isAccountNonLocked() {
		return true;
	}

	@Override
	public boolean isCredentialsNonExpired() {
		return true;
	}

	@Override
	public boolean isEnabled() {
		return true;
	}

	public Contact getContact() {
		return contact;
	}

	public void setContact(Contact contact) {
		this.contact = contact;
	}

	public SimpleGrantedAuthority getRole() {
		return role;
	}

	public void setRole(SimpleGrantedAuthority role) {
		this.role = role;
	}

}
